package com.xs.tool.common.constant;

import java.time.LocalTime;
import java.time.MonthDay;
import java.util.Locale;
import java.util.regex.Pattern;

/**
 * 通用常量信息
 *
 * @author ruoyi
 */
public class Constants
{
    /**
     * 后台管理系统用户名cookie名
     */
    public static final String ADMIN_COOKIE_USERNAME = "admin_username";
    /**
     * 后台管理系统密码cookie名
     */
    public static final String ADMIN_COOKIE_PASSWORD = "admin_password";
    /**
     * 后台管理系统记住我cookie名
     */
    public static final String ADMIN_COOKIE_REMEMBERME = "admin_rememberMe";
    /**
     * 7天的秒数
     */
    public static final int SECONDS_7_DAYS = 604800;
    /**
     * UTF-8 字符集
     */
    public static final String UTF8 = "UTF-8";

    /**
     * 通用成功标识
     */
    public static final String SUCCESS = "0";

    /**
     * 通用失败标识
     */
    public static final String FAIL = "1";

    /**
     * 登录成功
     */
    public static final String LOGIN_SUCCESS = "Success";

    /**
     * 注销
     */
    public static final String LOGOUT = "Logout";

    /**
     * 登录失败
     */
    public static final String LOGIN_FAIL = "Error";

    /**
     * 自动去除表前缀
     */
    public static final String AUTO_REOMVE_PRE = "true";

    /**
     * 当前记录起始索引
     */
    public static final String PAGE_NUM = "pageNum";

    /**
     * 每页显示记录数
     */
    public static final String PAGE_SIZE = "pageSize";

    /**
     * 排序列
     */
    public static final String ORDER_BY_COLUMN = "orderByColumn";

    /**
     * 排序的方向 "desc" 或者 "asc".
     */
    public static final String IS_ASC = "isAsc";

    /**
     * 资源映射路径 前缀
     */
    public static final String RESOURCE_PREFIX = "/profile";

    //===========================数值定义============================
    /**
     * 每天小时数
     */
    public static final int HOURS_PER_DAY = 24;

    /**
     * 每小时分钟数
     */
    public static final int MINUTES_PER_HOUR = 60;

    /**
     * 每分钟秒数
     */
    public static final int SECONDS_PER_MINUTE = 60;

    /**
     * 每秒毫秒数
     */
    public static final int MILLISECOND_PER_SECONDS = 1000;

    /**
     * 每天秒数
     */
    public static final int SECONDS_PER_DAY = HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE;

    /**
     * 每天毫秒数
     */
    public static final int MILLISECOND_PER_DAY = SECONDS_PER_DAY * MILLISECOND_PER_SECONDS;

    //===========================异常定义============================
    /**
     * 解析日期时异常
     */
    public static final String PARSE_LOCAL_DATE_EXCEPTION = "Unable to obtain";

    //===========================正则定义============================

    /**
     * 纯数字
     */
    public static final Pattern NUMERIC_REGEX = Pattern.compile("[0-9]+");

    /**
     * 字母开头
     */
    public static final Pattern START_WITH_WORD_REGEX = Pattern.compile("^[A-Za-z].*");

    /**
     * 中文
     */
    public static final Pattern CHINESE_REGEX = Pattern.compile("[\u4E00-\u9FFF]");

    //===========================时间定义============================

    /**
     * 1点
     */
    public static final LocalTime ONECLOCK = LocalTime.of(1, 0, 0);

    /**
     * 23点
     */
    public static final LocalTime TWENTYTHREECLOCK = LocalTime.of(23, 0, 0);

    /**
     * MonthDay 默认解析前缀
     * 解析字符串需要加前缀，如"--12-03"
     * @see java.time.MonthDay#parse(CharSequence)
     */
    public static final String MONTHDAY_FORMAT_PRE = "--";

    /**
     * 月日的起始值 01-01
     */
    public static final MonthDay MONTH_DAY_START = MonthDay.parse(MONTHDAY_FORMAT_PRE +"01-01");

    /**
     * 月日的终止值 12-31
     */
    public static final MonthDay MONTH_DAY_END = MonthDay.parse(MONTHDAY_FORMAT_PRE +"12-31");

    /**
     * 摩羯座的起始日期 12-22
     */
    public static final MonthDay CAPRICORN_START = MonthDay.parse(MONTHDAY_FORMAT_PRE +"12-22");

    /**
     * 摩羯座的终止日期 01-19
     */
    public static final MonthDay CAPRICORN_END = MonthDay.parse(MONTHDAY_FORMAT_PRE +"01-19");

    //===========================其他定义============================

    /**
     * 中文
     */
    public static final String ZH = "zh";

    /**
     * 除夕，节日处理使用
     */
    public static final String CHUXI = "CHUXI";

    /**
     * 春节，节日处理使用
     */
    public static final String CHUNJIE = "0101";

    private static volatile Constants constant;

    private Constants(){
    }

    public static Constants getInstance(){
        if(constant == null){
            synchronized(Constants.class){
                if(constant == null){
                    constant = new Constants();
                }
            }
        }
        return constant;
    }

    //===========================常用方法============================

    /**
     * 是否为中文语言环境
     * @return boolean
     */
    public static boolean isChineseLanguage(){
        return Locale.getDefault().getLanguage().equals(ZH);
    }

}
